package rapheal;

import java.io.*;
import java.util.*;
import java.util.Map.Entry;

class Attri{
	int attributesNamesId;
	String attributeName;
	int count;
}
public class NumAttriHavingArticleMoreThanX {
	//Load Raphael's data
	//attributeId, articleId, textId, templateId, templateName, attributeName, attributeValueWiki, attributeValueHtml, attributeValueText, attributesNamesId
	public static void main2(String []args)throws Exception{
		BufferedReader br = ioUtility.FileAccess.OpenLineRead("O:/unix/projects/pardosa/s2/raphaelh/data/all/attributes.all","ASCII");
		OutputStreamWriter osw = ioUtility.FileAccess.OpenWriteFile("C:/Users/clzhang/MyData/Wikipedia/attriNamesId_count", "ASCII");
		String line = "";
		HashMap<Integer,Attri>map = new HashMap<Integer,Attri>();
		int ln = 0;
		while((line = br.readLine())!=null){
			if(ln %10000==0)System.out.print(".");
			if(ln % 1000000 == 0)System.out.println();
			ln++;
			//System.out.println(line);
			String []abc = line.split("\t");
//			if(abc[5].equals("longm")){
//				System.out.println(abc[5]+"\t"+abc[9]);
//			}
			int a = Integer.parseInt(abc[9]);
			if(!map.containsKey(a)){
				Attri att = new Attri();
				att.attributeName = abc[5];
				att.attributesNamesId = a;
				att.count = 1;
				map.put(a, att);
			}else{
				Attri att = map.get(a);
				att.count ++;
			}
		}
		ln = 0;
		System.out.println("\nBegin Writing\n");
		Iterator<Entry<Integer,Attri>>it = map.entrySet().iterator();
		while(it.hasNext()){
			if(ln %10000==0)System.out.print(".");
			if(ln % 1000000 == 0)System.out.println();
			
			Entry<Integer,Attri> e = it.next();
			Attri att = e.getValue();
			if(att.count > 8){
				osw.write(att.attributesNamesId+"\t"+att.count+"\t"+att.attributeName+"\n");
				ln++;
			}
		}
		br.close();
		
		
	}
	
	//attributeId, articleId, textId, templateId, templateName, attributeName, attributeValueWiki, attributeValueHtml, attributeValueText, attributesNamesId
	public static void main(String []args)throws Exception{
		BufferedReader br = ioUtility.FileAccess.OpenLineRead("C:/Users/clzhang/MyData/Wikipedia/attriNamesId_count_sortCount","ASCII");
		String line = "";
		int res = 0;
		while((line = br.readLine())!=null){
			String []abc = line.split("\t");
			int x = Integer.parseInt(abc[1]);
			if(x>8000){
				res++;
			}
		}
		System.out.println(res);

	}
}
